package com.wly.packet;

import java.lang.reflect.Method;
import java.util.logging.Logger;

import com.google.protobuf.Message.Builder;

public abstract class SCPacket extends Packet
{
	protected Builder _builder;
	
	static private final String BUILDER_METHOD = "newBuilder";
	static private final Logger logger = Logger.getLogger("SCPacket");
	
	public SCPacket()
	{
		super();
		createBuilder();
	}
	
	public Builder getBuilder()
	{
		return _builder;
	}
	
	private void createBuilder()
	{
//		_bulder = IntMessage.newBuilder();
//		//_bulder =
		
		try
		{
			Class cls = Class.forName(getGPBClassName());
			Method parseMethod = cls.getMethod(BUILDER_METHOD);
			_builder = (Builder) parseMethod.invoke(null, null);
		}
		catch(Exception e)
		{
			logger.info("create builder failed!"+this.getClass());
			e.printStackTrace();
		}
	}
	
	public void build()
	{
		content = _builder.build();
	}
}
